module.exports = (app) => {
    const { STRING, INTEGER, DATE, ENUM, TEXT } = app.Sequelize;
  
    const Class = app.model.define("class", {
      id: {
        type: INTEGER(20),
        primaryKey: true,
        autoIncrement: true,
      },
      name: {
        type: STRING,
        allowNull: false,
        defaultValue: "",
        comment: "班级名称",
      },
      order: {
        type: INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: "排序",
      },
      created_time: {
        type:DATE,
        get(){
           return app.formatTime(this.getDataValue('created_time'))
        }
      },
      updated_time: DATE,
    });
    Class.associate = function (){
      // class与student是一对多关系，所以这里使用hasMany()
      app.model.Class.hasMany(app.model.User, {foreignKey: 'class_id', targetKey: 'id'});
      app.model.Class.hasMany(app.model.Exam, {foreignKey: 'class_id', targetKey: 'id'});
      app.model.Class.hasMany(app.model.Score, {foreignKey: 'class_id', targetKey: 'id'});
  }
  
    return Class;
  };